package com.traffic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.traffic.domain.PerEmergencyDispatchApplication;
import com.traffic.service.IPerEmergencyDispatchApplicationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 出警申请Controller
 * 
 * @author 郭世纪
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/emergency")
public class PerEmergencyDispatchApplicationController extends BaseController
{
    @Autowired
    private IPerEmergencyDispatchApplicationService perEmergencyDispatchApplicationService;

    /**
     * 查询出警申请列表
     */
    @RequiresPermissions("attendance:emergency:list")
    @GetMapping("/list")
    public TableDataInfo list(PerEmergencyDispatchApplication perEmergencyDispatchApplication)
    {
        startPage();
        List<PerEmergencyDispatchApplication> list = perEmergencyDispatchApplicationService.selectPerEmergencyDispatchApplicationList(perEmergencyDispatchApplication);
        return getDataTable(list);
    }

    /**
     * 导出出警申请列表
     */
    @RequiresPermissions("attendance:emergency:export")
    @Log(title = "出警申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PerEmergencyDispatchApplication perEmergencyDispatchApplication)
    {
        List<PerEmergencyDispatchApplication> list = perEmergencyDispatchApplicationService.selectPerEmergencyDispatchApplicationList(perEmergencyDispatchApplication);
        ExcelUtil<PerEmergencyDispatchApplication> util = new ExcelUtil<PerEmergencyDispatchApplication>(PerEmergencyDispatchApplication.class);
        util.exportExcel(response, list, "出警申请数据");
    }

    /**
     * 获取出警申请详细信息
     */
    @RequiresPermissions("attendance:emergency:query")
    @GetMapping(value = "/{overtimeId}")
    public AjaxResult getInfo(@PathVariable("overtimeId") Long overtimeId)
    {
        return success(perEmergencyDispatchApplicationService.selectPerEmergencyDispatchApplicationByOvertimeId(overtimeId));
    }

    /**
     * 新增出警申请
     */
    @RequiresPermissions("attendance:emergency:add")
    @Log(title = "出警申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PerEmergencyDispatchApplication perEmergencyDispatchApplication)
    {
        return toAjax(perEmergencyDispatchApplicationService.insertPerEmergencyDispatchApplication(perEmergencyDispatchApplication));
    }

    /**
     * 修改出警申请
     */
    @RequiresPermissions("attendance:emergency:edit")
    @Log(title = "出警申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PerEmergencyDispatchApplication perEmergencyDispatchApplication)
    {
        return toAjax(perEmergencyDispatchApplicationService.updatePerEmergencyDispatchApplication(perEmergencyDispatchApplication));
    }

    /**
     * 删除出警申请
     */
    @RequiresPermissions("attendance:emergency:remove")
    @Log(title = "出警申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{overtimeIds}")
    public AjaxResult remove(@PathVariable Long[] overtimeIds)
    {
        return toAjax(perEmergencyDispatchApplicationService.deletePerEmergencyDispatchApplicationByOvertimeIds(overtimeIds));
    }
}
